# Importing Data
US<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Magnesium/Magnesium.xlsx",sheet = "Sheet1", range = "H1:H264")

# Checking the Imported Data
View(US)
# Creating Time Series Data
US_ts <- ts(US, start=c(1998,1), end=c(2018,12), frequency=12)
# Viewing and Checking the Created Time Series Data
US_ts
sum(is.na(US_ts))
library(forecast)
US_ts <- tsclean(US_ts)
US_ts

# Identification: Plotting the Time Series Data
plot(US_ts)

# Estimating the appropriate model
US_ts_model <- auto.arima(US_ts)
US_ts_model

# Forecasting
options(max.print=1000000)
US_ts_forecast <- forecast (US_ts_model, level=c(95), h=264)
plot(US_ts_forecast)
US_ts_forecast             

# Exporting
write.table(US_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Magnesium/US_TSA.csv", sep=",")
